import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';

import '../../../common/app_theme.dart';
import '../../../common/colors.dart';
import '../../../common/tool.dart';
import '../../../components/base_scaffold_appbar.dart';
import '../../../services/address.dart';
import 'department_controller.dart';

class DepartMentView extends GetView{

  DepartMentController controller = Get.put(DepartMentController());

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: BaseAppBar(child: Text('选择部门'),
        preferredSize: Size(Get.width, AppTool.appBarHEIGHT),),
      body: GetBuilder<DepartMentController>(builder: (_){
        return Container(
          child: EasyRefresh.custom(
            slivers: [
              // SliverToBoxAdapter(
              //   child:Container(
              //       decoration: BoxDecoration(
              //           color: Colors.grey.shade200,
              //           borderRadius: BorderRadius.all(Radius.circular(13))),
              //       width: Get.width - 120,
              //       alignment: Alignment.centerLeft,
              //       margin: EdgeInsets.only(top:5, left: 15, right: 15),
              //       padding: EdgeInsets.only(left: 15),
              //       height: 25,
              //       child: Row(
              //         children: [
              //           Icon(
              //             Icons.search,
              //             size: 20,
              //             color: AppColor.smallTextColor,
              //           ),
              //           Container(
              //             alignment: Alignment.center,
              //             color: Colors.transparent,
              //             width: Get.width - 170,
              //             height: 30,
              //             child: TextField(
              //               controller: controller.editingController,
              //               onChanged: (values) {
              //                 controller.requestDataWithHrEmployee(values);
              //               },
              //               decoration: InputDecoration(
              //                   isCollapsed: true,
              //                   border: InputBorder.none,
              //                   hintText: '请输入关键词',
              //                   hintStyle: TextStyle(
              //                       color: AppColor.hintColor, fontSize: 13)),
              //               style: TextStyle(
              //                   color: AppColor.smallTextColor, fontSize: 14),
              //             ),
              //           )
              //         ],
              //       )),
              // ),

              SliverList(delegate: _departmentSliverChildBuilderDelegate(),),
            ],
          ),
        );
      }),
    );
  }
  _departmentSliverChildBuilderDelegate(){
    return SliverChildBuilderDelegate(
            (BuildContext context, int index) {
          return GestureDetector(
            onTap: (){
              var params = {
                'name':'${controller.model?.data?[index].name}',
                'id':'${controller.model?.data?[index].id}',
              };
              Get.back(result: params);
            },
            child: Container(
              color: Colors.transparent,
              child:Column(
                children: [
                  Container(
                    padding: EdgeInsets.all(10),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            CircleAvatar(
                              backgroundImage: NetworkImage(
                                '${Address.homeHost}${controller.model?.data?[index].image128}',
                              ),
                            ),
                            SizedBox(width: 5,),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text('${controller.model?.data?[index].name}',style: appThemeData.textTheme.bodyText1,),
                              ],
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                  Container(
                    color: AppColor.lineColor,
                    height: 1,
                  )
                ],
              ),
            ),
          );
        },
        childCount: controller.model?.data?.length??0
    );
  }


}